package com.spark.core.transformation

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * mapValues
 * 针对K,V格式的数据，只对Value做操作，Key保持不变
 */
object Demo23_mapValues {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("mapValues")
    conf.setMaster("local")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val infos: RDD[(String, String)] = sc.makeRDD(List[(String, String)](("zhangsna", "18"),
      ("lisi", "20"), ("wangwu", "30")))

    // name不变, 年龄翻倍
    val result: RDD[(String, String)] = infos.mapValues(age => {
      age.toInt + 2 + ""
    })

    result.foreach(println)

  }
}
